﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MockPrjTeam1.Entity;
using MockPrjTeam1.Biz;
using System.Windows.Forms;

namespace MockPrjTeam1.Pages.Views
{
    public partial class AddProgramme : System.Web.UI.Page
    {
        string id = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            id = Convert.ToString(Request.QueryString["id"]);
            if (!string.IsNullOrEmpty(id))
            {
                var biz1 = new ProgrammeBiz();
                var pro = new Programme();
                pro = biz1.GetOne(Convert.ToInt32(id));
                TextBox1.Text = pro.ProgrammeName;
                TextBox2.Text = pro.Description;
                txtContact.Text = pro.ContactName;
                if (pro.Active)
                    CheckBox1.Checked = false;
                else
                    CheckBox1.Checked = true;
            }
        }

        protected void Save_Click(object sender, EventArgs e)
        {
            ProgrammeBiz biz = new ProgrammeBiz();
            Programme programme = new Programme();
            programme.ProgrammeName = TextBox1.Text;
            programme.Description = TextBox2.Text;
            programme.ContactName = txtContact.Text;
            if (CheckBox1.Checked)
            {
                programme.Active = false;
            }
            else
                programme.Active = false;
                
            if (string.IsNullOrEmpty(id))
            {

                if (biz.Btn_Save_Programme(programme, "A"))
                {
                    Response.Redirect("../Views/ListProgramme.aspx");
                }
                else
                {
                    
                }
            }
            else
            {
                if (biz.Btn_Save_Programme(programme, "E"))
                {
                    Response.Redirect("../Views/ListProgramme.aspx");
                }
            }
        }
    }
}